import QuestionParagraph from "./QuestionParagraph";
import QuestionTitle from "./QuestionTitle";
import QuestionInput from "./QuestionInput";
import QuestionTextarea from "./QuestionTextarea";
import QuestionRadio from "./QuestionRadio";
import QuestionCheckbox from "./QuestionCheckbox";

type ComponentInfoType = {
  id: string;
  type: string;
  isHidden: boolean;
  props: any;
  answer: string;
};

export const getComponent = (comp: ComponentInfoType) => {
  const { id, type, isHidden, props, answer } = comp;
  const formatProps = answer !== undefined ? { ...props, answer } : props;

  if (isHidden) return null;

  switch (type) {
    case "questionTitle":
      return <QuestionTitle {...props} />;
    case "questionParagraph":
      return <QuestionParagraph {...props} />;
    case "questionInput":
      return <QuestionInput id={id} props={formatProps} />;
    case "questionTextarea":
      return <QuestionTextarea id={id} props={formatProps} />;
    case "questionRadio":
      return <QuestionRadio id={id} props={formatProps} />;
    case "questionCheckbox":
      return <QuestionCheckbox id={id} props={formatProps} />;
    default:
      return null;
  }
};
